<%@ page language="java" import="com.ruohi.util.common.CommonApplication,com.ruohi.util.common.CommonString"
         pageEncoding="UTF-8" %>
<%@ page import="com.ruohi.util.common.Env" %>
<%@ page import="java.util.Map" %>
<%
	String tableName = "gift_miaosha";
	String tablePrefix = Env.getInstance().getProperty("table_prefix");
	String fileds = "id,add_date,uuid,product_no,begin_time,alert_count,status,is_sale,(select name from gift_product where gift_product.no=gift_miaosha.product_no) as product_name";
	String channelUUID = CommonString.getFormatPara(request.getParameter("channel_uuid"));
	String whereStr = " ";
	String orderByStr = " id desc ";
	
	Map enumMap116 = (Map)CommonApplication.getEnumChildren("116",application);
%><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <title><%=Env.getInstance().getProperty("project_name") %></title>
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/Gray/css/all.css" rel="stylesheet" type="text/css" />
	<link href="/plugin/ui/ligerUI/ligerUI/skins/ligerui-icons.css" rel="stylesheet" type="text/css" />
	<link href="/backend/style/style.css" rel="stylesheet" type="text/css" />
	<script src="/plugin/jquery/jquery.min.js" type="text/javascript"></script>
  </head>
  <body>
  	<div class="searchForm">
  		<div class="searchCondition">
            <div class="searchList">
		  		<div class="searchLeft">开始日期</div>
		  		<div class="searchRight">
		  			<input type="text" class="Wdate jr_text" onclick="WdatePicker({dateFmt:'yyyy-MM-dd'});" name="start_date" id="start_date" />
		  		</div>
		  	</div>
  		</div>
  		<div class="searchBtn">
  			<input type="button" class="btn" onclick="doSearch();" value="查询" /><input type="button" style="margin-left: 5px;" class="btn" onclick="doClearForm();" value="重置" />
  		</div>
  	</div>
  	<div style="clear: left;"></div>
  	
	<div class="l-loading" style="display: block" id="pageloading"></div> 
	<div id="maingrid" style="margin: 0; padding: 0"></div>
	<div style="display: none;"></div>
  </body>
</html>
<script src="/plugin/ui/ligerUI/ligerUI/js/ligerui.min.js" type="text/javascript"></script>
<script src="/plugin/date/My97DatePicker/WdatePicker.js" type="text/javascript"></script>
<script src="/backend/scripts/common.js" prefix="<%=tablePrefix %>" type="text/javascript"></script>
<script type="text/javascript">
	var grid;
	var windowWidth = 700;
	var windowHeight = 240;
	var channelUUID = '<%=channelUUID %>';
	var tableName = "<%=tableName %>";
	var fields = "<%=fileds %>";
	var whereStr = "<%=whereStr %>";
	var orderBy = "<%=orderByStr %>";
	var columnsArr = [];
	var url = "";
	var conditionStr = "";
	var params = [];
	jQuery(function() {
		params.push({'name':'enumNo','value':'106013'});
		grid = new Dev21sunGrid();
		jQuery("#pageloading").hide();
	});
	var is_showData = [{ is_show : 1 , text: '是' }, { is_show : 0 , text: '否'}];
	//列数组
	columnsArr =  [ 
		{ display : '秒杀状态', name : 'status', align : 'center' , type : 'int' , width : 100 , render : function(row){
				var str = "";
				switch(row.status){
					case 0:
						str = "下期秒杀";
					break;
					case 1:
						str = "本期秒杀";
					break;
					case -1:
						str = "往期秒杀";
					break;
				}
				return str;
			}
		} ,
		{ display : '秒杀产品', name : 'product_name', align : 'left' , type : 'string' , width : 300, render:function(row){
            return "<a target='_blank' href='http://www.52sdskj.com/product/" + row.product_no + ".htm'><img class='preview' src='/plugin/ui/ligerUI/ligerUI/skins/icons/preview.png' />" + row.product_name + "</a>";
		} }  ,
		{ display : '开始时间', name : 'begin_time', align : 'center' , type : 'string' , width : 200 } ,
		{ display:"提醒使用次数", name:"alert_count", align:"center", type:"int", width:100 },
		{ display:"是否卖完", name:"is_sale", align:"center", type:"int", width:100, render:function(row){
			return row.is_sale == 1 ? "已卖完" : "未卖完";
		} },
		{ display:"操作", align:"center", width:200, render:function(row){
			var email = "&nbsp;&nbsp;";
			if(row.status==1){
				email += "<a class='link' href='javascript://void(0);' onclick='send_miaosha_alert();'>发送提醒邮件</a>";
			}
			return "<a class='link' href='javascript:void(0);' onclick='addAndEdit("+row.__index+");'>编辑</a>"+email;
		} }
	];
	
	/*列表页条件查询*/
	function doSearch(){
		params = [];
		conditionStr = "";
		var start_date = jQuery("#start_date").val();
		if(''!=jQuery.trim(start_date)){
			conditionStr += " and add_date >= '"+start_date+"' ";
		}
		params.push({'name':'enumNo','value':'106013'});
		params.push({'name':'tableName','value':tableName});
		params.push({'name':'fileds','value':fields});
		params.push({'name':'whereStr','value':whereStr+conditionStr});
		params.push({'name':'orderBy','value':orderBy});
		grid.options.parms=params;
		grid.loadData();
	}
	
	function addAndEdit(index){
		if(undefined==index){//如果是增加
			toolbarAdd({
				width:500,
				height:300,
				title:"增加",
				params : {
	    			channel_uuid : "<%=channelUUID %>"
	    		}
			});
		}else{//如果是修改
	    	var row = grid.getRow(index);
	    	toolbarAdd({width:500,height:300,title:'编辑'},row.uuid);
		}
    }
    
    function send_miaosha_alert(){
    	jrConfirm("确定要发送秒杀提醒吗？", function(v) {
			if (v) {
				$.ajax({
		    		type:"post",
		    		url:"/backend/action/ajax_r.jsp",
		    		data:{flag:"sendMiaoshaAlert",enumNo:"106013"}
		    	});
		    	jrSuccess("已发送！");
			}
		});
    }
</script>